﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Maticsoft.DBUtility;

namespace ElingOA6_Admin_DSJCJ.DAL
{
    /// <summary>
    /// 操作日志DAL
    /// </summary>
    public  class OperateLog_MVC
    {
        /// <summary>
        /// 增加日志操作数据
        /// <creator>zhongyl</creator>
        /// <date>2013-07-10</date>
        /// </summary>
        /// <param name="model">操作日志信息</param>
        ///<returns>是否增加成功</returns>
        public int AddOperateLog(Model.OperateLog_MVC model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into t_OperateLog_MVC(");
            strSql.Append("FLogID,FLogName,FStartTime,FOverTime,FOperateContent,FOperateProp,FOperatePropValue,FOperateLevel,FHost,FCip,FVisitAddress,FParam,FMethod,FUserAgent,FSessionID,FBrowser,FOS,FNote)");
            strSql.Append(" values (");
            strSql.Append("@FLogID,@FLogName,@FStartTime,@FOverTime,@FOperateContent,@FOperateProp,@FOperatePropValue,@FOperateLevel,@FHost,@FCip,@FVisitAddress,@FParam,@FMethod,@FUserAgent,@FSessionID,@FBrowser,@FOS,@FNote)");
            strSql.Append(";select IDENT_CURRENT('t_OperateLog')");
            SqlParameter[] parameters = {
					new SqlParameter("@FLogID", SqlDbType.NVarChar,30),
					new SqlParameter("@FLogName", SqlDbType.NVarChar,40),
					new SqlParameter("@FStartTime", SqlDbType.DateTime),
					new SqlParameter("@FOverTime", SqlDbType.DateTime),
					new SqlParameter("@FOperateContent", SqlDbType.NVarChar,255),
					new SqlParameter("@FOperateProp", SqlDbType.NVarChar,255),
					new SqlParameter("@FOperatePropValue", SqlDbType.NVarChar,255),
					new SqlParameter("@FOperateLevel", SqlDbType.Char,1),
					new SqlParameter("@FHost", SqlDbType.NVarChar,80),
					new SqlParameter("@FCip", SqlDbType.NVarChar,15),
					new SqlParameter("@FVisitAddress", SqlDbType.NVarChar,255),
					new SqlParameter("@FParam", SqlDbType.NVarChar,255),
					new SqlParameter("@FMethod", SqlDbType.NVarChar,80),
					new SqlParameter("@FUserAgent", SqlDbType.NVarChar,200),
					new SqlParameter("@FSessionID", SqlDbType.NVarChar,64),
					new SqlParameter("@FBrowser", SqlDbType.NVarChar,255),
					new SqlParameter("@FOS", SqlDbType.NVarChar,255),
					new SqlParameter("@FNote", SqlDbType.NVarChar,200)};
            parameters[0].Value = model.FLogID;
            parameters[1].Value = model.FLogName;
            parameters[2].Value = model.FStartTime;
            parameters[3].Value = model.FOverTime;
            parameters[4].Value = model.FOperateContent;
            parameters[5].Value = model.FOperateProp;
            parameters[6].Value = model.FOperatePropValue;
            parameters[7].Value = model.FOperateLevel;
            parameters[8].Value = model.FHost;
            parameters[9].Value = model.FCip;
            parameters[10].Value = model.FVisitAddress;
            parameters[11].Value = model.FParam;
            parameters[12].Value = model.FMethod;
            parameters[13].Value = model.FUserAgent;
            parameters[14].Value = model.FSessionID;
            parameters[15].Value = model.FBrowser;
            parameters[16].Value = model.FOS;
            parameters[17].Value = model.FNote;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
    }
}
